package com.vlin.api.client.request.defaut;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.http.client.methods.HttpUriRequest;

import com.vlin.api.client.Method;
import com.vlin.api.client.Params;
import com.vlin.api.client.request.RequestProducer;
import com.vlin.api.client.request.RequestProducerManager;

public class DefaultedRequestProducer implements RequestProducer,RequestProducerManager {

	Map<Method, RequestProducer> cache = new ConcurrentHashMap<>();
	
	public DefaultedRequestProducer() {
		cache.put(Method.GET, new DefaultedGETRequestProducer());
		cache.put(Method.POST, new DefaultedPOSTRequestProducer());
	}
	
	@Override
	public HttpUriRequest produceRequest(String url, Method method, Params params) {
		RequestProducer requestProduer = cache.get(method);
		return requestProduer.produceRequest(url, method, params);
	}

	@Override
	public void setRequestProduer(RequestProducer requestProducer) {
		cache.put(requestProducer.getMethod(), requestProducer);
		
	}

	@Override
	public List<RequestProducer> getRequestProduer() {
		
		return Arrays.asList(cache.values().toArray(new RequestProducer[] {}));
	}

	@Override
	public boolean supportMethod(Method method) {
		
		return true;
	}

	@Override
	public Method getMethod() {
		return null;
	}

}
